package com.projects.android.bus;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

import com.projects.android.utils.Utils;

public class ValidationBUS {
	public static String validateUser(String user, String pass) {
		String errTxt = "";
		try {
			Map<String, String> mapUser = new HashMap<String, String>();
			mapUser.put("username", user);
			mapUser.put("password", pass);
			String url = Utils.buildURL(Utils.SERVICE_URI
					+ "/Validation_ValidateUser", mapUser);
			
			// Send GET request to <service>/GetPlates
			HttpClient httpClient = new DefaultHttpClient();
			HttpGet request = new HttpGet(new URI(url));
			request.setHeader("Accept", "application/json");
			request.setHeader("Content-type", "application/json");

			HttpResponse response = httpClient.execute(request);
			HttpEntity responseEntity = response.getEntity();
			// Read response data into buffer
			errTxt = Utils.getResponse(responseEntity);
			errTxt = errTxt.replace('"', ' ').trim();
			Log.i("ValidationBUS validateUser", "Response: " + errTxt.replace('"', ' ').trim());
		} catch (Exception e) {
			Log.e("ValidationBUS validateUser", e.toString());
		}
		return errTxt;
	}
}
